this.addEventListener('install', function (event) {
  event.waitUntil(
    caches.open('test-cache')
      .then(function (cache) {
        return cache.addAll(['./', './index.html'])
      })
  )
})

this.addEventListener('fetch', function (event) {
  event.respondWith(
    caches.match(event.request)
      .then(function (response) {
        if (response) {
          return response;
        }
        var request = event.request.clone();
        return fetch(request)
          .then(function (httpRes) {
            if (!httpRes || httpRes.status !== 200) {
              return htpsRes;
            }
            var responseClone = httpRes.clone();
            caches.open('test-cache-v1')
              .then(function (cache) {
                cache.put(event.request, responseClone)
              })

          })
      })
  )
})